package com.example.zk2_lx;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.view.MenuItem;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.zk2_lx.adapter.MyFragAdapter;
import com.example.zk2_lx.databinding.ActivityImactivityBinding;
import com.example.zk2_lx.mvvm_base.BaseViewActivity;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.List;

@Route(path = "/app/IMActivity")
public class IMActivity extends BaseViewActivity<ActivityImactivityBinding> {
    List<Fragment> list = new ArrayList<>();
    MyFragAdapter myFragAdapter;

    @Override
    protected int bindLayout() {
        return R.layout.activity_imactivity;
    }

    @Override
    protected void initView() {
        list.add(new ConsFragment());
        list.add(new FriendFragment());
        myFragAdapter = new MyFragAdapter(this,list);
        dataBinding.vp.setAdapter(myFragAdapter);


        //联动
        dataBinding.vp.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                dataBinding.bottom.getMenu().getItem(position).setChecked(true);
            }
        });
        dataBinding.bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.item_cons:
                        dataBinding.vp.setCurrentItem(0);
                        break;
                    case R.id.item_friend:
                        dataBinding.vp.setCurrentItem(1);
                        break;
                }
                return false;
            }
        });


    }

    @Override
    protected void initData() {

    }
}